<?php 
session_start();

include("../../conexion.php");
	require_once("../../includes/barramenu.php") ;
	require_once("../../includes/gridView.php")  ;
	require_once("../../includes/combo.php")  	  ;
	$oBarra = new BarraMenu() 				  ;
	$Grid1 = new GridView()					  ;
	$oCombo = new CmbList()  				  ;	
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cancelacion de Documentos</title>
<link href="../../includes/css/jquery-ui-notarios.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="../../tcal.css" />
<link href="../../includes/css/jquery-ui-notarios.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="../../includes/css/uniform.default.min.css" />
<link rel="stylesheet" type="text/css" href="../../tcal.css" />

<script type="text/javascript" src="../../tcal.js"></script> 
<script type="text/javascript" src="../includes/Mantenimientos.js"></script> 
<script src="../../includes/jquery-1.8.3.js"></script>
<script src="../../includes/js/jquery-ui-notarios.js"></script>
<script src="../../includes/jquery.uniform.min.js"></script>
<script src="../../includes/maskedinput.js"></script>
<script type="text/javascript" src="../../tcal.js"></script> 

<style type="text/css">
div.carta_content {
	background:#333333;
	border: 1px solid #333333;
	-moz-border-radius: 10px;
	-webkit-border-radius: 10px;
	border-radius: 10px;
	-moz-box-shadow: 0px 0px 7px #000000;
	-webkit-box-shadow: 0px 0px 7px #000000;
	box-shadow: 0px 0px 7px #000000;
	width:638px;
	height:220px;
	position:absolute;
	left: 549px;
	top: 496px;
	margin-top: 15px;
	margin-left: -450px;
	opacity: 0.95;
	filter: "alpha(opacity=50)"; /* expected to work in IE 8 */
	filter: alpha(opacity=50);   /* IE 4-7 */
	zoom: 1;
}

div.allcontrata {width:600px; height:150px; overflow:auto;}
.titupatrimo {font-size: 12; font-style: italic; font-family: Calibri;}

div.div_bloques
{ 
background-color: #ffffff;
border: 4px solid #264965;  
-moz-border-radius: 13px;
-webkit-border-radius: 13px;
border-radius: 13px;
-moz-box-shadow: 0px 0px 5px #000000;
-webkit-box-shadow: 0px 0px 5px #000000;
box-shadow: 0px 0px 5px #000000;
width:820px; height:750px;
}

.camposss {font-family: Calibri; font-style: italic; font-size: 14px; color: #333333; }


#field_remitente, #field_destinatario, #field_responpago, #field_diligencia, #field_cargo{
	margin:0 auto;
	border: 2px solid #ddd; 
	border-radius: 10px; 
	padding: 2px; 
	box-shadow: #ccc 5px 0 5px;
	margin-bottom:0px;
	}

.fielSetTipoVista{
	width:100%;
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	color:#000;
	font-weight:bold;
	border:#000 solid 1px;
	box-shadow: #ccc 5px 0 10px;
	border-radius: 10px; 
	}
	
</style>
<script type="text/javascript">

$(window).ready(function(){ 

	 ShowDetComprobante()
	 $('#div_buscadoc').attr('style','display:none');
	 $('#fAgregarItem').attr('style','display:none');
	 
	 $('#cboBusca').val('2');

	 //$("input, textarea, select, button").uniform();
	 $("input, textarea").uniform();
	 $("button").button();
	 $("#dialog").dialog();
	 //$("#div_bloques").sortable();
	 
	 ShowCCarac();
	 
	 $(".ui-dialog-titlebar").hide();
	 //muestragrid();
	})

jQuery(function($){
    $("#fec_ingreso").mask("99/99/9999",{placeholder:"_"});
});

// #==============================================================


////////
function NumCheck(e, field) {
key = e.keyCode ? e.keyCode : e.which
// backspace

if (key == 8) return true
if(key==13){
//document.getElementById("bpag").focus();
}
// 0-9
if (key > 47 && key < 58) {
if (field.value == "") return true
regexp = /.[0-9]{*}$/
return !(regexp.test(field.value))
}
// .
if (key == 46) {
if (field.value == "") return false
regexp = /^[0-9]+$/
return regexp.test(field.value)
}
// other key
return false
}
////////

function fGraba2()
{
	var _numdoc		  = document.getElementById('num_docu');
	var _solicitante  = document.getElementById('nombre'); 

	if(_numdoc.value=='' || _solicitante.value=='')
	{alert('Faltan ingresar datos');return;}
	
	else 
	{
		$( "#muesguarda" ).dialog({
			resizable: false,
			height:140,
			position :["center","top"],
			modal: true,
			buttons: {
				"Aceptar": function() { fevalguarda();
					//$( this ).dialog( "close" );
				},
				"Cancelar": function() {
					$( this ).dialog( "close" );
				}
			}
		});
	}	
}
// #==============================================================
function fevalguarda()
{
	
	fguardaCambio();
	$("#muesguarda").dialog("close");
    //$("#muesguarda").remove();
}
// #==========================================================================
// #==========================================================================
function ShowCCarac()
{
$('#div_cambiocar').load('listdetCCarac.php');		
}

function fAddDetalle()
{
	var _id_cambio = document.getElementById('id_cambio').value;
	var _detalle = document.getElementById('detalle_cambios').value;
	
	if(_id_cambio == '')
	{
		alert('Debe ingresar y grabar los datos primero...');return;
	}
	else if(_id_cambio != '')	
	{
		if(_detalle == ''){alert('Debe seleccionar la caracteristica');return;}
		fPassData();
		//$('#div_cambiocar').load('listdetCCarac.php?detalle='+_detalle+'&id_cambio='+_id_cambio);
	}
	
}

// #=============================================================

function fPassData2()
{
	var _id_cambio = document.getElementById('id_cambio').value;
	var _detalle = document.getElementById('detalle_cambios').value;
	$('#div_cambiocar').load('listdetCCarac.php?detalle='+_detalle+'&id_cambio='+_id_cambio);	
}

// #=============================================================

function fElimDetalle()
{
	var _id_cambio = document.getElementById('id_cambio').value;
	var _detalle = document.getElementById('detalle_cambios').value;
	
	if(_id_cambio == '')
	{
		alert('Debe ingresar y grabar los datos primero...');return;
	}
	else if(_id_cambio != '')	
	{
		if(_detalle == ''){alert('Debe seleccionar la caracteristica a eliminar');return;}
		fElimData();
		//$('#div_cambiocar').load('listdetCCarac.php?detalle='+_detalle+'&id_cambio='+_id_cambio);
	}
	
}
 
function fElimData2()
{
	var _id_cambio = document.getElementById('id_cambio').value;
	var _detalle = document.getElementById('detalle_cambios').value;
	$('#div_cambiocar').load('listdetCCarac.php?detalle='+_detalle+'&id_cambio='+_id_cambio);	
	//alert('Se elimino satisfactoriamente');	
}	
// #========== AGREGAR NEW PARTICIPANTES ===============# 
function newParticipante()
{
	//var _id_viaje = document.getElementById('id_viaje').value;
	//var _id_contratante = "";
	
var divobs = $('<div id="div_newpartic" title="div_newpartic"></div>');
// carga con ajax y abre el dialog.
$('<div id="div_newpartic" title="div_newpartic"></div>').load('NewRemitente.php')
.dialog({
				autoOpen: true,
				position :["center","top"],
                width   : 720,
                height  : 350,
                modal:false,
                resizable:false,
				//show: 'clip',
				//hide: 'clip',
				buttons: [{id: "btnAcepPartic2", text: "Aceptar",click: function() {/*$(this).dialog("close");*/ }},
				{text: "Cancelar",click: function() {$(this).dialog("close"); }}],
                title:'Agregar participantes'
				
                }).width(720).height(350);	
				$(".ui-dialog-titlebar").hide();		
}


// ################
// ################
function ShowDetComprobante()
{
	
	var _firsteval = "0";
$('#div_detalle').load('listDocsPen.php?evalbus='+_firsteval);		
}

function fTipoBusq()
{
	var _tipbus = $('#cboBusca').val();	
	if(_tipbus=='1') 	   // x documento
	{
		$('#txtcodigo').val('');
		$('#txtnombre').val('');
		$('#txtdireccion').val('');
		$('#tipdocu').val('');
		$('#txtserie').val('');
		$('#txtnumdocu').val('');
		$('#div_buscaclie').attr('style','display:none');
		$('#div_buscadoc').removeAttr('style');
	}
	else if(_tipbus=='2')  // x codigo de cliente
	{
		$('#txtcodigo').val('');
		$('#txtnombre').val('');
		$('#txtdireccion').val('');
		$('#tipdocu').val('');
		$('#txtserie').val('');
		$('#txtnumdocu').val('');
		$('#div_buscadoc').attr('style','display:none');
		$('#div_buscaclie').removeAttr('style');
	}
}
 
function fBuscaDoc()
{
	var _evalbus     = $('#cboBusca').val();  //  #1- documento  #2. Codigo Cliente.
	var _codigo_cli  = $('#txtcodigo').val();
	var _tipo_docu   = $('#tipdocu').val();
	var _serie       = $('#txtserie').val();
	var _documento   = $('#txtnumdocu').val();	
	
	if(_evalbus=='1') 	   // x documento
	{
		$('#div_detalle').load('listDocsPen.php?evalbus='+_evalbus+'&tipo_docu='+_tipo_docu+'&serie='+_serie+'&documento='+_documento);
	}
	else if(_evalbus=='2')  // x codigo de cliente
	{
		$('#div_detalle').load('listDocsPen.php?evalbus='+_evalbus+'&codigo_cli='+_codigo_cli);
	}		
} 

function PagarDocu(_obj)
{
	var _id_ctaventas = _obj ;
	var _vars = fShowAjaxDato('../includes/DatosCtaCte.php?id_ctaventas='+_id_ctaventas);
	document.getElementById('datosCC').value = _vars;
	//alert(document.getElementById('datosCC').value);
	var _datos = document.getElementById('datosCC').value;
	
	_datos = _datos.split('|');
	
		var _id_ctaventas = _datos[0];
		var _tipdoc       = _datos[7];
		var _cliente      = _datos[6];
		var _fecha        = _datos[4];
		var _forpago      = _datos[10];
		//var _concepto     = _datos[1];
		var _monto        = _datos[15];
		var _saldo        = _datos[16];
		var _serie        = _datos[2];
		var _numdoc       = _datos[3];
		//var _emple        = _datos[1];
		var _swtdet       = _datos[17];
		var _montodet     = _datos[18];
		var _banco        = _datos[11];
		var _numero       = _datos[12];
	
	document.getElementById('id_ctaventas').value = _id_ctaventas;	
	document.getElementById('tipdocu2').value = _tipdoc;	
	document.getElementById('cliente').value = _cliente;
	document.getElementById('txtfecha').value = _fecha;	
	document.getElementById('tippago').value = _forpago;	
	document.getElementById('txtmonto').value = _monto;	
	document.getElementById('txtsaldo').value = _saldo;	
	document.getElementById('seriedoc').value = _serie;	
	document.getElementById('numdocumen').value = _numdoc;	
	document.getElementById('txtmonreten').value = _montodet;
		
	/*if(_montodet=='0.00' || _montodet=='')
	{
		document.getElementById('swtreten').checked = false;
	}
	else if(parseFloat(_montodet) > 0.00)
	{
		document.getElementById('swtreten').checked = true;	
	}*/
	
	document.getElementById('txtbanco').value = _banco;	
	document.getElementById('numcta').value = _numero;		
	
	
	//$('#fAgregarItem').removeAttr('style');
	$('#fAgregarItem').fadeIn();
		
}

function fOcultaAdd()
{	
	$('#id_ctaventas').val('');
	$('#tipdocu2').val('');
	$('#cliente').val('');
	$('#tippago').val('');
	$('#txtmonto').val('');
	$('#txtsaldo').val('');
	$('#seriedoc').val('');
	$('#numdocumen').val('');
	$('#txtmonreten').val('');
	$('#txtbanco').val('');
	$('#numcta').val('');
	//document.getElementById('swtreten').checked   = false;
	
	$('#fAgregarItem').fadeOut();
}
 
function fAgregaAdd()
{
	var _id_ctaventas = $('#id_ctaventas').val();
	var _tipdocu2     = $('#tipdocu2').val();
	var _cliente      = $('#cliente').val();
	var _tippago      = $('#tippago').val();
	var _txtmonto     = $('#txtmonto').val();
	var _txtsaldo     = $('#txtsaldo').val();
	var _seriedoc     = $('#seriedoc').val();
	var _numdocumen   = $('#numdocumen').val();
	var _txtmonreten  = $('#txtmonreten').val();
	var _txtbanco     = $('#txtbanco').val();
	var _numcta       = $('#numcta').val();	
	var _txtfecha     = $('#txtfecha').val();	
	
	if(_txtsaldo > _txtmonto)
	{alert('El monto a pagar supera el Monto total del documento');return;}
	
    if(_id_ctaventas == '')
	{
		alert('Debe seleccionar un documento a cancelar...');return;
	}
	else if(_id_ctaventas != '')	
	{
		if(_tipdocu2 =='' || _cliente == '' ||  _tippago == '' || _txtsaldo == '' || _seriedoc == '' || _numdocumen == '')
		{alert('Falta ingresar datos...');return;}
		
		fUpdateCtaCte();	
		//$('#fAgregarItem').fadeOut();
		
		//$('#div_cambiocar').load('listdetCCarac.php?detalle='+_detalle+'&id_cambio='+_id_cambio);
		//fCalculosGeneral();
	}
	
} 

 
</script>
</head>
<body style="font-size:62.5%;">
<div id="carta_content">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td>
     <?php
				//$oBarra->Nuevo        = "1"             ; 
				//$oBarra->NuevoClick   = "agregar();"    ;
				//$oBarra->Graba        = "1"               ;
				//$oBarra->GrabaClick   = "fGraba2();"      ;
				//$oBarra->Impri        = "1"               ;
				//$oBarra->ImpriClick   = "fImprimir();"    ;
				//$oBarra->refresh      = "1"          	  ;
				//$oBarra->refreshClick = "frefresh();"   ;
				//$oBarra->Elimi      = "1"           	  ;
				//$oBarra->ElimiClick = "fElimina();"  	  ;
				$oBarra->Busca      = "1"           	  ;
				$oBarra->itemBusca  = "Documento, Cliente"; 
				$oBarra->BuscaClick = "//fTipoBusq()"     ;
				$oBarra->cmbClick   = "fTipoBusq()"       ;
			    //$oBarra->onKeytxt   = "focusSearch(event)";
				$oBarra->clase        = "css"      		    ; 
				$oBarra->widthtxt   = "15"				    ;  
				$oBarra->Show()  						    ; 
				?>
    </td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  <tr>
    <td width="637">&nbsp;</td>
  </tr>
  <tr>
    <td><input name="datosCC" type="hidden" id="datosCC" />
    <fieldset id="field_remitente">
    <legend><span class="camposss">Detalles</span>
    </legend>
    <div id="div_buscaclie">
    <table  width="100%">
        <tr>
          <td width="8%"><span class="camposss">N°Doc:</span> </td>
          <td width="8%"><input name="txtcodigo" type="text" id="txtcodigo" style="text-transform:uppercase" onKeyPress="//fShowDatosProvee(event);" size="16" /></td>
          <td width="10%" align="right"><span class="camposss">Nombre:</span></td>
          <td colspan="2"><input name="txtnombre" type="text" id="txtnombre" style="text-transform:uppercase" onKeyPress="//fShowDatosProvee(event);" size="60" /></td>
          </tr>
        <tr>
          <td><span class="camposss">Dirección:</span> </td>
          <td colspan="3"><input name="txtdireccion" style="text-transform:uppercase" type="text" id="txtdireccion" size="60" /></td>
          <td width="48%"><span class="camposss">Buscar Documentos</span>&nbsp;<button title="buscar" type="button" name="buscardoc"    id="buscardoc" value="Buscar" onclick="fBuscaDoc();" ><img src="../../images/search.png" alt="" width="15" height="15" /></button></td>
          </tr>
        </table>
        </div>
        <div id="div_buscadoc">
        <table  width="100%">
        <tr>
          <td width="11%"><span class="camposss">Tipo Doc:</span> </td>
          <td colspan="4"><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT tip_documen.id_documen AS 'id', tip_documen.des_docum AS 'des' FROM tip_documen ORDER BY tip_documen.des_docum ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "120"; 
			$oCombo->name       = "tipdocu";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "//selectFactIni();";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td>
          </tr>
        <tr>
          <td><span class="camposss">Serie:</span> </td>
          <td width="9%"><input name="txtserie" style="text-transform:uppercase" type="text" id="txtserie" size="5" /></td>
          <td width="8%" align="right"><span class="camposss">Documento N°:</span></td>
          <td width="26%"><input name="txtnumdocu" type="text" id="txtnumdocu" style="text-transform:uppercase" onKeyPress="//fShowDatosProvee(event);" size="16" /></td>
          <td width="46%"><span class="camposss">Buscar Documento</span>&nbsp;<button title="buscar" type="button" name="buscardoc2"    id="buscardoc2" value="Buscar" onclick="fBuscaDoc();" ><img src="../../images/search.png" alt="" width="15" height="15" /></button></td>
        </tr>
        </table>
        </div>
    </fieldset>  
      </td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
          <td colspan="2">
            <div id="fAgregarItem" class="fielSetTipoVista">
				<table border="0" width="100%">
    				<tr>
        				<td width="18%" align="right">Tipo de Documento:</td>
        				<td width="23%"><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT tip_documen.id_documen AS 'id', tip_documen.des_docum AS 'des' FROM tip_documen ORDER BY tip_documen.des_docum ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "120"; 
			$oCombo->name       = "tipdocu2";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "//selectFactIni();";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td>
        				<td width="32%" colspan="3" align="right">N° Documento:</td>
                        <td width="27%"><input name="seriedoc" type="text" id="seriedoc" style="text-transform:uppercase" size="1" readonly="readonly" />-
                      <input name="numdocumen" type="text" id="numdocumen" style="text-transform:uppercase" size="10" readonly="readonly" /></td>
        			</tr>
    				<tr>
    				  <td align="right">Cliente:</td>
    				  <td><input name="cliente" type="text" id="cliente" style="text-transform:uppercase;" size="50" readonly="readonly" /></td>
    				  <td colspan="3" align="right">Empleado:</td>
    				  <td><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT usuarios.loginusuario AS 'id' ,CONCAT(usuarios.apepat,' ',usuarios.apemat, ', ',usuarios.prinom) AS 'des' FROM usuarios
ORDER BY usuarios.apepat ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "150"; 
			$oCombo->name       = "grupoemp";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "//selectzona(this.value);";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td>
  				  </tr>
    				<tr>
    				  <td align="right">Fecha:</td>
    				  <td><input name="txtfecha" type="text" id="txtfecha" style="text-transform:uppercase;" size="10" readonly="readonly" /></td>
    				  <td align="right"><!--Id:--></td>
    				  <td><input name="id_ctaventas" type="hidden" id="id_ctaventas" /></td>
    				  <td colspan="2"><div id="aplica_detrac"><span class="detraccion2"><span class="detraccion21">
            <!--<input id="swtreten" name="swtreten" type="checkbox" value="0" onChange="EvalDetrac();">-->
          </span><!--Con Retención--></span>
   				        <input name="txtmonreten" type="hidden" id="txtmonreten"/>
    				  </div></td>
   				  </tr>
    				<tr>
    				  <td align="right">Forma de Pago</td>
    				  <td align="left"><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT tipo_pago.codigo AS 'id', tipo_pago.descrip AS 'des' FROM tipo_pago ORDER BY tipo_pago.descrip ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "150"; 
			$oCombo->name       = "tippago";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "//selectzona(this.value);";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td>
    				  <td align="right">Banco</td>
    				  <td align="left"><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT bancos.desbanco AS 'id', bancos.desbanco AS 'des' 
FROM bancos"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "130"; 
			$oCombo->name       = "txtbanco";
			$oCombo->style      = ""; 
			$oCombo->click      = "//selectAsunto(this.value);";   
			//$oCombo->selected   =  $rowpat['fpago'];
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td>
    				  <td align="right">Número:</td>
    				  <td align="left"><input name="numcta" type="text" id="numcta" style="text-transform:uppercase;" value="0" size="15" /></td>
			      </tr>
    				<tr>
    				  <td align="right">Concepto</td>
    				  <td colspan="5" align="left"><input name="concepto" type="text" id="concepto" style="text-transform:uppercase; " value="CANCELACION DE DOCUMENTO" size="50" /></td>
   				  </tr>
    				<tr>
    				  <td align="right">Monto:</td>
    				  <td colspan="5" align="left"><input name="txtsaldo" type="text" id="txtsaldo" style="text-transform:uppercase; text-align:right;" value="0.00" size="15" onkeypress="return NumCheck(event, this);" />
   				      <input name="txtmonto" type="hidden" id="txtmonto"/></td>
   				  </tr>
    				<tr>
    				  <td>&nbsp;</td>
    				  <td align="center">&nbsp;</td>
    				  <td colspan="3" align="center">&nbsp;</td>
    				  <td align="center"><button title="Agregar" type="button" name="agregarAdd"    id="agregarAdd" value="Agregar" onclick="fAgregaAdd();" ><img src="../../images/success.png" alt="" width="18" height="18" /></button> &nbsp;&nbsp;   				    <button title="Cerrar" type="button" name="cerrarAdd"    id="cerrarAdd" value="Cerrar" onclick="fOcultaAdd();" ><img src="../../images/delete.png" alt="" width="18" height="18" /></button></td>
  				  </tr>
    			</table>
			</div>
          </td>
          </tr>
          <tr><td>&nbsp;</td></tr>
  <tr>
    <td>
 <div id="div_detalle" style='border: 1px solid #264965;border-radius: 5px;width:100%; height:390px; overflow:auto;'></div>
    </td>
    </tr>
  <tr>
    <td >&nbsp;</td>
  </tr>
</table>
</div>
</body>
</html>